import axios from 'axios'
axios.defaults.withCredentials = true
// const urlNavtive = '/api'
// const urlNavtive = 'http://localhost:3000'
const urlNavtive = 'https://r.leaguenewway.com'
// const urlNavtive = 'https://r.leaguenewway.com/uniapi'
export interface typeCalss {
  type_id: string
  type_name: string
  type_ids?: number[]
  index?: number
}

export function getClass() {
  return axios({
    url: `${urlNavtive}/newVideoInfo/getClass`
  })
}

export interface navClass {
  type_name: string
  type_id: number
}

export function getClassNav() {
  return axios({
    url: `${urlNavtive}/newVideoInfo/getClassNav`
  })
}

export interface getListParams {
  name?: string
  type_id?: string
  orderType?: number
  vod_id?: number
  year?: string
  searchSame?: number
}

export function getList(count: number, page: number, params: getListParams) {
  return axios({
    url: `${urlNavtive}/newVideoInfo/getList`,
    params: {
      count,
      page,
      ...params
    }
  })
}

export interface typeSwiper {
  type_id: string
  vod_name: string
  vod_info: string
  vod_img: string
  vod_img_small: string
  vod_id: string
  vod_index: number
}

export function getSwiper(type_id: string) {
  return axios({
    url: `${urlNavtive}/newVideoInfo/getSwiper`,
    params: {
      type_id
    }
  })
}

export function register(user: string, password: string, confirmPassword: string) {
  return axios({
    method: 'post',
    url: `${urlNavtive}/newVideoInfo/register`,
    data: {
      user,
      password,
      confirmPassword
    },
    responseType: 'json'
  })
}

export function login(user: string, password: string) {
  return axios({
    method: 'post',
    url: `${urlNavtive}/newVideoInfo/login`,
    data: {
      user,
      password
    },
    responseType: 'json'
  })
}

export function getUserInfo() {
  return axios({
    url: `${urlNavtive}/newVideoInfo/getUserInfo`
  })
}

export function loginOut() {
  return axios({
    method: 'post',
    url: `${urlNavtive}/newVideoInfo/loginOut`
  })
}

export function getComment(vid: number) {
  return axios({
    url: `${urlNavtive}/newVideoInfo/getComment`,
    params: {
      vid
    }
  })
}

export function postComment(vid: number, com: string) {
  return axios({
    url: `${urlNavtive}/newVideoInfo/postComment`,
    method: 'post',
    data: {
      vid,
      com
    }
  })
}

export function editUserInfo(username?: string, password?: string, newPassword?: string) {
  return axios({
    method: 'post',
    url: `${urlNavtive}/newVideoInfo/editUserInfo`,
    data: {
      username,
      password,
      newPassword
    },
    responseType: 'json'
  })
}

export function upVideoHistry(v: any) {
  window.navigator.sendBeacon(`${urlNavtive}/newVideoInfo/upVideoHistry`, JSON.stringify(v))
  // return axios({
  //   method: 'post',
  //   url: `${urlNavtive}/newVideoInfo/upVideoHistry`,
  //   data: v,
  //   responseType: 'json'
  // })
}

export function getVideoHistry() {
  return axios({
    url: `${urlNavtive}/newVideoInfo/getVideoHistry`,
    responseType: 'json'
  })
}

export function checkPassword(password: string) {
  return axios({
    method: 'post',
    url: `${urlNavtive}/newVideoInfo/checkPassword`,
    data: { password },
    responseType: 'json'
  })
}
